IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SaveAdvanceFundRequestEmailNotification]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SaveAdvanceFundRequestEmailNotification]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO



--SaveAdvanceFundRequestEmailNotification 41359, 41359, '2009A050008', 'ACTION: Advance Fund Request has been submitted', 'ACTION NEEDED: An advance fund request has been submitted for your approval.', 2

CREATE PROCEDURE [dbo].[SaveAdvanceFundRequestEmailNotification] 
(  
	@fwkDomainUserId	INT,
	@EmailedToId	INT,	
	@PropNumber	VARCHAR(50),
	@Subject	VARCHAR(500),
	@MessageBody	VARCHAR(3000),
	@StatusType	INT
)  
AS 

SET NOCOUNT ON

		DECLARE @AFRId INT
		
		SET @AFRId = (SELECT Id FROM dbo.AdvanceFundRequest WHERE PropNumber = @PropNumber)
		IF (ISNULL(@AFRId, 0) > 0)
		BEGIN
			INSERT INTO dbo.AdvanceFundRequestEmailNotification (AdvanceFundRequestId, AdvanceFundRequestStatusTypeId, EmailedTo, EmailedBy, Subject, MessageBody) 
				VALUES (@AFRId, @StatusType, @EmailedToId, @fwkDomainUserId, @Subject, @MessageBody)
		END

GO